package com.sql;

import io.swagger.models.auth.In;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;

public class SqlFormatter {
    public static void main(String[] args) {
        System.out.println(111);
        BigDecimal a =BigDecimal.TEN;
        Integer b = null;
        System.out.println(a.compareTo(BigDecimal.ZERO));
        String formattedSql =" SELECT deviceBindSensorLast.id id,\n"
                + "\tdeviceBindSensorLast.license_plate licensePlate,\n"
                + "\tdeviceSensor.sensor_type sensorType,\n"
                + "\tdeviceSensor.manufacturer_id manufacturerId,\n"
                + "\tdeviceBindSensorLast.location tyreLocation,\n"
                + "\tdeviceBindSensorLast.sensor_id sensorId,\n"
                + "\tdeviceTypePressureLast.pressure,\n"
                + "\tdeviceTypePressureLast.temperature,\n"
                + "\tdeviceTypePressureLast.is_receive_data_timeout onlineStatus \n"
                + "FROM\n"
                + "\tdevice_bind_sensor_last deviceBindSensorLast\n"
                + "\tLEFT JOIN device_tyre_pressure_last deviceTypePressureLast "
                + " ON deviceTypePressureLast.license_plate = deviceBindSensorLast.license_plate \n"
                + "\tAND deviceTypePressureLast.location = deviceBindSensorLast.location \n"
                + "\tAND deviceTypePressureLast.pressure_sensor_id = deviceBindSensorLast.sensor_id \n"
                + "\tAND deviceTypePressureLast.is_deleted = 0\n"
                + "\tLEFT JOIN device_sensor deviceSensor ON deviceSensor.sensor_id = deviceBindSensorLast.sensor_id \n"
                + "WHERE\n"
                + "\tdeviceBindSensorLast.is_deleted = 0 \n"
                + "\tAND deviceBindSensorLast.license_plate = :licensePlate "
                + " AND deviceBindSensorLast.device_id = :deviceId ";

        String singleLineSql = formatSqlToSingleLine(formattedSql);
        System.out.println(singleLineSql);
    }

    public static String formatSqlToSingleLine(String formattedSql) {
        return formattedSql.replaceAll("\\s+", " ").trim();
    }
}
